Using OLR
#vclust <- varclus (~ angle + building+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana , data=train.data)
# took out density since training has 0 d4 and it was not allowing do the plot
#p <- plot(vclust)
par(mfrow=c(8,4))
plot.xmean.ordinaly (risk~ angle+ density+building+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito + TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana
Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)
#library(plyr)
angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
mutate("Percentage"=(freq/106)*100)%>%
mutate("Classifier" = "angle")
building <- count(train.data$building) %>% #(445, 46, 39)
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "building")
density <- count(train.data$density) %>% #(79, 415, 36) # d4 =0
mutate ("Percentage"=(freq/132.5)*100)%>%
mutate("Classifier" = "density")
EN <- count(train.data$EN) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "EN")
TC <- count(train.data$TC) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "TC")
TC_MatureSoil <- count(train.data$TC_mature_Soil) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_MatureSoil")
TC_Saprolito <- count(train.data$TC_saprolito) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_Saprolito")
TC_WRock <- count(train.data$TC_weath_rock) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_WRock")
TC_rock <- count(train.data$TC_rock) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_rock")
TC_geol_desfav <- count(train.data$TC_geol_desfav) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC_geol_desfav")
Taterro <- count(train.data$Taterro) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "Taterro")
DepEncNatural <- count(train.data$DepEncNatural) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "TC")
DepTaludeAterro <- count(train.data$DepTaludeAterro) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepEncNatural")
DepTaludeCorte <- count(train.data$DepTaludeCorte) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeCorte")
DepTaludeAterro <- count(train.data$DepTaludeAterro) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
construction_deposit <- count(train.data$construction_deposit) %>%
mutate ("Percentage"=(freq/265)*100) %>%
mutate("Classifier" = "construction_deposit")
garbage <- count(train.data$garbage) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "garbage")
crack <- count(train.data$crack) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "crack")
leaning_wall <- count(train.data$leaning_wall) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "leaning_wall")
scars <- count(train.data$scars) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
downward_floor <- count(train.data$downward_floor) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "scars")
tilted <- count(train.data$tilted) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tilted")
fracture <- count(train.data$fracture) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "fracture")
conc_rainfall_water <- count(train.data$conc_rainfall_water) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "DepTaludeAterro")
leak <- count(train.data$leak) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "conc_rainfall_water")
wastewater <- count(train.data$wastewater) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "wastewater")
septic_tank <- count(train.data$septic_tank) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "septic_tank")
drainage <- count(train.data$drainage) %>%
mutate ("Percentage"=(freq/176.7)*100)%>%
mutate("Classifier" = "drainage")
tree <- count(train.data$tree) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "tree")
ground_veg <- count(train.data$ground_veg) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "ground_veg")
deforestation <- count(train.data$deforestation) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "deforestation")
banana <- count(train.data$banana) %>%
mutate ("Percentage"=(freq/265)*100)%>%
mutate("Classifier" = "banana")
df <- rbind(TC, TC_MatureSoil, TC_Saprolito, TC_WRock, TC_rock, TC_geol_desfav, Taterro, DepEncNatural, DepTaludeAterro, DepTaludeCorte,construction_deposit, garbage, crack, leaning_wall,
scars, downward_floor, tilted, fracture, conc_rainfall_water, leak, wastewater, septic_tank, drainage, tree, ground_veg, deforestation, banana,
angle,
building, density, EN
)
df
## x freq Percentage Classifier
## 1 FALSE 46 17.3584906 TC
## 2 TRUE 483 182.2641509 TC
## 3 FALSE 274 103.3962264 TC_MatureSoil
## 4 TRUE 255 96.2264151 TC_MatureSoil
## 5 FALSE 451 170.1886792 TC_Saprolito
## 6 TRUE 78 29.4339623 TC_Saprolito
## 7 FALSE 518 195.4716981 TC_WRock
## 8 TRUE 11 4.1509434 TC_WRock
## 9 FALSE 528 199.2452830 TC_rock
## 10 TRUE 1 0.3773585 TC_rock
## 11 FALSE 517 195.0943396 TC_geol_desfav
## 12 TRUE 12 4.5283019 TC_geol_desfav
## 13 FALSE 469 176.9811321 Taterro
## 14 TRUE 60 22.6415094 Taterro
## 15 FALSE 395 149.0566038 TC
## 16 TRUE 134 50.5660377 TC
## 17 FALSE 510 192.4528302 DepTaludeAterro
## 18 TRUE 19 7.1698113 DepTaludeAterro
## 19 FALSE 310 116.9811321 DepTaludeCorte
## 20 TRUE 219 82.6415094 DepTaludeCorte
## 21 FALSE 322 121.5094340 construction_deposit
## 22 TRUE 207 78.1132075 construction_deposit
## 23 FALSE 355 133.9622642 garbage
## 24 TRUE 174 65.6603774 garbage
## 25 FALSE 444 167.5471698 crack
## 26 TRUE 85 32.0754717 crack
## 27 FALSE 497 187.5471698 leaning_wall
## 28 TRUE 32 12.0754717 leaning_wall
## 29 FALSE 322 121.5094340 DepTaludeAterro
## 30 TRUE 207 78.1132075 DepTaludeAterro
## 31 FALSE 469 176.9811321 scars
## 32 TRUE 60 22.6415094 scars
## 33 FALSE 433 163.3962264 tilted
## 34 TRUE 96 36.2264151 tilted
## 35 FALSE 528 199.2452830 fracture
## 36 TRUE 1 0.3773585 fracture
## 37 FALSE 23 8.6792453 DepTaludeAterro
## 38 TRUE 506 190.9433962 DepTaludeAterro
## 39 FALSE 345 130.1886792 conc_rainfall_water
## 40 TRUE 184 69.4339623 conc_rainfall_water
## 41 FALSE 220 83.0188679 wastewater
## 42 TRUE 309 116.6037736 wastewater
## 43 FALSE 526 198.4905660 septic_tank
## 44 TRUE 3 1.1320755 septic_tank
## 45 Y 63 35.6536503 drainage
## 46 P 239 135.2574986 drainage
## 47 N 227 128.4663271 drainage
## 48 FALSE 223 84.1509434 tree
## 49 TRUE 306 115.4716981 tree
## 50 FALSE 162 61.1320755 ground_veg
## 51 TRUE 367 138.4905660 ground_veg
## 52 FALSE 490 184.9056604 deforestation
## 53 TRUE 39 14.7169811 deforestation
## 54 FALSE 363 136.9811321 banana
## 55 TRUE 166 62.6415094 banana
## 56 A 3 2.8301887 angle
## 57 B 46 43.3962264 angle
## 58 C 82 77.3584906 angle
## 59 D 293 276.4150943 angle
## 60 E 105 99.0566038 angle
## 61 B 459 259.7623090 building
## 62 W 39 22.0713073 building
## 63 M 31 17.5438596 building
## 64 d1 83 62.6415094 density
## 65 d2 414 312.4528302 density
## 66 d3 32 24.1509434 density
## 67 FALSE 348 131.3207547 EN
## 68 TRUE 181 68.3018868 EN
TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)
f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)
# Equation 1
eq_OLR_01 <- polr(risk~ building + TC_saprolito +
Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte +
landfill + garbage + construction_deposit + crack +
leaning_wall + scars + downward_floor +tilted +
conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank + TC_mature_Soil + deforestation, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## building.L 0.07094632 0.3336430 0.21264144 4.158033e-01
## building.Q -0.91120855 0.4059388 -2.24469450 1.239388e-02
## TC_saprolitoTRUE -0.34737837 0.3089876 -1.12424681 1.304542e-01
## TaterroTRUE -0.20983077 0.3773479 -0.55606713 2.890825e-01
## DepEncNaturalTRUE -0.01146158 0.3744275 -0.03061095 4.877899e-01
## DepTaludeAterroTRUE 0.52538982 0.6968580 0.75394105 2.254423e-01
## DepTaludeCorteTRUE 0.49454633 0.3120840 1.58465793 5.652204e-02
## landfillTRUE 0.16610019 0.3239652 0.51270999 3.040771e-01
## garbageTRUE 0.46351801 0.3642848 1.27240543 1.016146e-01
## construction_depositTRUE -0.32671167 0.3612172 -0.90447431 1.828720e-01
## crackTRUE 1.81113915 0.3437891 5.26816864 6.889575e-08
## leaning_wallTRUE 1.53540429 0.5103865 3.00831697 1.313495e-03
## scarsTRUE 4.23860691 0.4168321 10.16861926 1.368809e-24
## downward_floorTRUE 1.60422390 0.3998411 4.01215323 3.008371e-05
## tiltedTRUE 0.83857882 0.3350905 2.50254447 6.165207e-03
## conc_rainfall_waterTRUE 2.00815900 0.5384577 3.72946488 9.594342e-05
## wastewaterTRUE 0.73377024 0.2333716 3.14421399 8.326681e-04
## leakTRUE -0.03021594 0.2409709 -0.12539252 4.501064e-01
## treeTRUE 0.16158956 0.2462373 0.65623504 2.558365e-01
## ground_vegTRUE 0.99736210 0.2712461 3.67696389 1.180132e-04
## bananaTRUE 0.20834658 0.2600855 0.80106954 2.115457e-01
## septic_tankTRUE -0.10852067 1.5260101 -0.07111399 4.716535e-01
## TC_mature_SoilTRUE 0.63349693 0.2255451 2.80873695 2.486813e-03
## deforestationTRUE -0.01750063 0.3900026 -0.04487312 4.821042e-01
## R1|R2 1.35724196 0.5650755 2.40187718 8.155592e-03
## R2|R3 5.32097384 0.6381140 8.33859414 3.758948e-17
## R3|R4 10.83562282 0.7936361 13.65313808 9.668439e-43
stargazer((ctable), type="text", style="default", digits = 2)
##
## =========================================================
## Value Std. Error t value p value
## ---------------------------------------------------------
## building.L 0.07 0.33 0.21 0.42
## building.Q -0.91 0.41 -2.24 0.01
## TC_saprolitoTRUE -0.35 0.31 -1.12 0.13
## TaterroTRUE -0.21 0.38 -0.56 0.29
## DepEncNaturalTRUE -0.01 0.37 -0.03 0.49
## DepTaludeAterroTRUE 0.53 0.70 0.75 0.23
## DepTaludeCorteTRUE 0.49 0.31 1.58 0.06
## landfillTRUE 0.17 0.32 0.51 0.30
## garbageTRUE 0.46 0.36 1.27 0.10
## construction_depositTRUE -0.33 0.36 -0.90 0.18
## crackTRUE 1.81 0.34 5.27 0.0000
## leaning_wallTRUE 1.54 0.51 3.01 0.001
## scarsTRUE 4.24 0.42 10.17 0
## downward_floorTRUE 1.60 0.40 4.01 0.0000
## tiltedTRUE 0.84 0.34 2.50 0.01
## conc_rainfall_waterTRUE 2.01 0.54 3.73 0.0001
## wastewaterTRUE 0.73 0.23 3.14 0.001
## leakTRUE -0.03 0.24 -0.13 0.45
## treeTRUE 0.16 0.25 0.66 0.26
## ground_vegTRUE 1.00 0.27 3.68 0.0001
## bananaTRUE 0.21 0.26 0.80 0.21
## septic_tankTRUE -0.11 1.53 -0.07 0.47
## TC_mature_SoilTRUE 0.63 0.23 2.81 0.002
## deforestationTRUE -0.02 0.39 -0.04 0.48
## R1| R2 1.36 0.57 2.40 0.01
## R2| R3 5.32 0.64 8.34 0
## R3| R4 10.84 0.79 13.65 0
## ---------------------------------------------------------
less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ building + TC_saprolito +
Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte +
landfill + garbage + construction_deposit + crack +
leaning_wall + scars + downward_floor +tilted +
conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank + TC_mature_Soil + deforestation
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)
Equation 1
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~building + TC_saprolito +
Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte +
landfill + garbage + construction_deposit + crack +
leaning_wall + scars + downward_floor +tilted +
conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank + TC_mature_Soil + deforestation
, fun=sf))
s
## as.numeric(risk) N= 529
##
## +--------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC_saprolito |No |451|Inf | 1.8937244|-0.11097851|-2.05963891|
## | |Yes| 78|Inf | 2.4849066| 0.36290549|-1.70474809|
## +--------------------+---+---+----+----------+-----------+-----------+
## |Taterro |No |469|Inf | 1.8632184|-0.12382535|-2.10365580|
## | |Yes| 60|Inf | 3.3672958| 0.61903921|-1.38629436|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepEncNatural |No |395|Inf | 1.7002671|-0.46918092|-2.46316666|
## | |Yes|134|Inf | 3.4812401| 1.37699197|-1.15923691|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeAterro |No |510|Inf | 1.9236870|-0.10204925|-2.11296423|
## | |Yes| 19|Inf | Inf| 2.14006616|-0.31845373|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeCorte |No |310|Inf | 1.5561934|-0.39204209|-2.47793798|
## | |Yes|219|Inf | 2.9396428| 0.45518854|-1.52939520|
## +--------------------+---+---+----+----------+-----------+-----------+
## |landfill |No |331|Inf | 1.5490288|-0.57746278|-2.74406064|
## | |Yes|198|Inf | 3.3063633| 0.88119941|-1.28222500|
## +--------------------+---+---+----+----------+-----------+-----------+
## |garbage |No |355|Inf | 1.7181262|-0.33550652|-2.53796121|
## | |Yes|174|Inf | 2.6958549| 0.56639547|-1.30906301|
## +--------------------+---+---+----+----------+-----------+-----------+
## |construction_deposit|No |322|Inf | 1.6244195|-0.45488999|-2.39113849|
## | |Yes|207|Inf | 2.7880929| 0.60738036|-1.55814462|
## +--------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +--------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +--------------------+---+---+----+----------+-----------+-----------+
## |downward_floor |No |469|Inf | 1.8270276|-0.29639401|-2.45750768|
## | |Yes| 60|Inf | Inf| 4.07753744|-0.26826399|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +--------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water |No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +--------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leak |No |345|Inf | 1.6625477|-0.35737892|-2.59338729|
## | |Yes|184|Inf | 2.8564702| 0.55748132|-1.31317210|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tree |No |223|Inf | 1.3475083|-0.67972416|-2.37368101|
## | |Yes|306|Inf | 2.7150432| 0.41091471|-1.78415487|
## +--------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +--------------------+---+---+----+----------+-----------+-----------+
## |banana |No |363|Inf | 1.5995532|-0.40776132|-2.23766555|
## | |Yes|166|Inf | 3.7013020| 0.78495473|-1.59504917|
## +--------------------+---+---+----+----------+-----------+-----------+
## |septic_tank |No |526|Inf | 1.9590108|-0.04563529|-2.01275017|
## | |Yes| 3|Inf | Inf| 0.69314718|-0.69314718|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC_mature_Soil |No |274|Inf | 1.5493340|-0.32397207|-2.21355147|
## | |Yes|255|Inf | 2.6390573| 0.26028310|-1.80555279|
## +--------------------+---+---+----+----------+-----------+-----------+
## |deforestation |No |490|Inf | 2.0276865| 0.04082199|-1.96944065|
## | |Yes| 39|Inf | 1.3545457|-1.20397280|-2.48490665|
## +--------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +--------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1.5, cex.axis=1.5, cex.sub=1.5)
f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)
stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ angle +building + EN + TC_saprolito+ Taterro+ TC_mature_Soil+ DepEncNatural+ DepTaludeAterro+ DepTaludeCorte+ landfill+garbage+ construction_deposit+ leak+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree+ ground_veg+ banana+ deforestation + density+ TC,
data= train.data
, method = "logistic", Hess = TRUE)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
ctable <- coef(summary(eq_OLR_02))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## angleB -0.84788186 1.6826178 -0.50390639 3.071636e-01
## angleC 0.33075167 1.6672048 0.19838694 4.213712e-01
## angleD 0.86623957 1.6643160 0.52047783 3.013653e-01
## angleE 1.73154332 1.6772507 1.03237002 1.509494e-01
## building.L 0.08863771 0.3292826 0.26918434 3.938939e-01
## building.Q -1.14876125 0.4237232 -2.71111271 3.352891e-03
## ENTRUE 0.86790687 0.3818389 2.27296610 1.151411e-02
## TC_saprolitoTRUE -0.55909302 0.3259522 -1.71526087 4.314870e-02
## TaterroTRUE -0.14779141 0.3931371 -0.37592846 3.534850e-01
## TC_mature_SoilTRUE 0.44558998 0.2384024 1.86906663 3.080677e-02
## DepEncNaturalTRUE -0.65256017 0.4754871 -1.37240357 8.496892e-02
## DepTaludeAterroTRUE 0.92682842 0.7122352 1.30129546 9.657867e-02
## DepTaludeCorteTRUE 0.36686195 0.3338527 1.09887382 1.359116e-01
## landfillTRUE 0.34253753 0.3289970 1.04115706 1.489013e-01
## garbageTRUE 0.49227005 0.3793141 1.29778996 9.717976e-02
## construction_depositTRUE -0.23156955 0.3737954 -0.61950888 2.677906e-01
## leakTRUE -0.01132889 0.2499427 -0.04532597 4.819237e-01
## crackTRUE 1.79585420 0.3584548 5.00998773 2.721675e-07
## leaning_wallTRUE 1.35756400 0.4979579 2.72626265 3.202800e-03
## scarsTRUE 4.45479463 0.4303899 10.35060184 2.079317e-25
## downward_floorTRUE 1.62646688 0.4146012 3.92296710 4.373255e-05
## tiltedTRUE 0.80347723 0.3376836 2.37937917 8.670914e-03
## conc_rainfall_waterTRUE 1.63639207 0.6179825 2.64795841 4.048974e-03
## wastewaterTRUE 0.87212399 0.2477209 3.52059051 2.152935e-04
## treeTRUE 0.01201290 0.2550986 0.04709120 4.812203e-01
## ground_vegTRUE 0.67437265 0.2813377 2.39702215 8.264462e-03
## bananaTRUE 0.02952891 0.2710396 0.10894687 4.566223e-01
## deforestationTRUE -0.32509304 0.4042441 -0.80419992 2.106408e-01
## densityd2 0.28415914 0.3209598 0.88534191 1.879861e-01
## densityd3 0.13237882 0.5858140 0.22597414 4.106108e-01
## TCTRUE 0.85025534 0.4641643 1.83179816 3.349075e-02
## R1|R2 2.23358030 1.7627521 1.26709837 1.025601e-01
## R2|R3 6.61028550 1.7978169 3.67684023 1.180704e-04
## R3|R4 12.39604142 1.8824340 6.58511354 2.272690e-11
stargazer((ctable), type="text", style="default", digits=2)
##
## =========================================================
## Value Std. Error t value p value
## ---------------------------------------------------------
## angleB -0.85 1.68 -0.50 0.31
## angleC 0.33 1.67 0.20 0.42
## angleD 0.87 1.66 0.52 0.30
## angleE 1.73 1.68 1.03 0.15
## building.L 0.09 0.33 0.27 0.39
## building.Q -1.15 0.42 -2.71 0.003
## ENTRUE 0.87 0.38 2.27 0.01
## TC_saprolitoTRUE -0.56 0.33 -1.72 0.04
## TaterroTRUE -0.15 0.39 -0.38 0.35
## TC_mature_SoilTRUE 0.45 0.24 1.87 0.03
## DepEncNaturalTRUE -0.65 0.48 -1.37 0.08
## DepTaludeAterroTRUE 0.93 0.71 1.30 0.10
## DepTaludeCorteTRUE 0.37 0.33 1.10 0.14
## landfillTRUE 0.34 0.33 1.04 0.15
## garbageTRUE 0.49 0.38 1.30 0.10
## construction_depositTRUE -0.23 0.37 -0.62 0.27
## leakTRUE -0.01 0.25 -0.05 0.48
## crackTRUE 1.80 0.36 5.01 0.0000
## leaning_wallTRUE 1.36 0.50 2.73 0.003
## scarsTRUE 4.45 0.43 10.35 0
## downward_floorTRUE 1.63 0.41 3.92 0.0000
## tiltedTRUE 0.80 0.34 2.38 0.01
## conc_rainfall_waterTRUE 1.64 0.62 2.65 0.004
## wastewaterTRUE 0.87 0.25 3.52 0.0002
## treeTRUE 0.01 0.26 0.05 0.48
## ground_vegTRUE 0.67 0.28 2.40 0.01
## bananaTRUE 0.03 0.27 0.11 0.46
## deforestationTRUE -0.33 0.40 -0.80 0.21
## densityd2 0.28 0.32 0.89 0.19
## densityd3 0.13 0.59 0.23 0.41
## TCTRUE 0.85 0.46 1.83 0.03
## R1| R2 2.23 1.76 1.27 0.10
## R2| R3 6.61 1.80 3.68 0.0001
## R3| R4 12.40 1.88 6.59 0
## ---------------------------------------------------------
par(mfrow=c(7,4))
plot.xmean.ordinaly (risk~ angle +building + EN + TC_saprolito+ Taterro+ TC_mature_Soil+ DepEncNatural+ DepTaludeAterro+ DepTaludeCorte+ landfill+garbage+ construction_deposit+ leak+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree+ ground_veg+ banana+ deforestation + density+ TC
,data=train.data, cr=TRUE , subn=FALSE , cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~angle +building + EN + TC_saprolito+ Taterro+ TC_mature_Soil+ DepEncNatural+ DepTaludeAterro+ DepTaludeCorte+ landfill+garbage+ construction_deposit+ leak+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree+ ground_veg+ banana+ deforestation + density+ TC,data=train.data
, fun=sf))
s
## as.numeric(risk) N= 529
##
## +--------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------------+---+---+----+----------+-----------+-----------+
## |angle |A | 3|Inf | 0.6931472| -Inf| -Inf|
## | |B | 46|Inf |-0.3513979|-1.89711998|-3.80666249|
## | |C | 82|Inf | 1.6691571|-1.00330211|-3.27083556|
## | |D |293|Inf | 2.6137395| 0.33764251|-1.84451003|
## | |E |105|Inf | 3.2288262| 0.28768207|-1.50990832|
## +--------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +--------------------+---+---+----+----------+-----------+-----------+
## |EN |No |348|Inf | 1.5288574|-0.50470003|-2.51645501|
## | |Yes|181|Inf | 4.0831713| 0.88173835|-1.35889539|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC_saprolito |No |451|Inf | 1.8937244|-0.11097851|-2.05963891|
## | |Yes| 78|Inf | 2.4849066| 0.36290549|-1.70474809|
## +--------------------+---+---+----+----------+-----------+-----------+
## |Taterro |No |469|Inf | 1.8632184|-0.12382535|-2.10365580|
## | |Yes| 60|Inf | 3.3672958| 0.61903921|-1.38629436|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC_mature_Soil |No |274|Inf | 1.5493340|-0.32397207|-2.21355147|
## | |Yes|255|Inf | 2.6390573| 0.26028310|-1.80555279|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepEncNatural |No |395|Inf | 1.7002671|-0.46918092|-2.46316666|
## | |Yes|134|Inf | 3.4812401| 1.37699197|-1.15923691|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeAterro |No |510|Inf | 1.9236870|-0.10204925|-2.11296423|
## | |Yes| 19|Inf | Inf| 2.14006616|-0.31845373|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeCorte |No |310|Inf | 1.5561934|-0.39204209|-2.47793798|
## | |Yes|219|Inf | 2.9396428| 0.45518854|-1.52939520|
## +--------------------+---+---+----+----------+-----------+-----------+
## |landfill |No |331|Inf | 1.5490288|-0.57746278|-2.74406064|
## | |Yes|198|Inf | 3.3063633| 0.88119941|-1.28222500|
## +--------------------+---+---+----+----------+-----------+-----------+
## |garbage |No |355|Inf | 1.7181262|-0.33550652|-2.53796121|
## | |Yes|174|Inf | 2.6958549| 0.56639547|-1.30906301|
## +--------------------+---+---+----+----------+-----------+-----------+
## |construction_deposit|No |322|Inf | 1.6244195|-0.45488999|-2.39113849|
## | |Yes|207|Inf | 2.7880929| 0.60738036|-1.55814462|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leak |No |345|Inf | 1.6625477|-0.35737892|-2.59338729|
## | |Yes|184|Inf | 2.8564702| 0.55748132|-1.31317210|
## +--------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +--------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +--------------------+---+---+----+----------+-----------+-----------+
## |downward_floor |No |469|Inf | 1.8270276|-0.29639401|-2.45750768|
## | |Yes| 60|Inf | Inf| 4.07753744|-0.26826399|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +--------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water |No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +--------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tree |No |223|Inf | 1.3475083|-0.67972416|-2.37368101|
## | |Yes|306|Inf | 2.7150432| 0.41091471|-1.78415487|
## +--------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +--------------------+---+---+----+----------+-----------+-----------+
## |banana |No |363|Inf | 1.5995532|-0.40776132|-2.23766555|
## | |Yes|166|Inf | 3.7013020| 0.78495473|-1.59504917|
## +--------------------+---+---+----+----------+-----------+-----------+
## |deforestation |No |490|Inf | 2.0276865| 0.04082199|-1.96944065|
## | |Yes| 39|Inf | 1.3545457|-1.20397280|-2.48490665|
## +--------------------+---+---+----+----------+-----------+-----------+
## |density |d1 | 83|Inf | 0.8415672|-1.28401551|-3.28341435|
## | |d2 |414|Inf | 2.2633644| 0.05798726|-2.03143232|
## | |d3 | 32|Inf | 3.4339872| 1.94591015|-0.51082562|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC |No | 46|Inf | 0.6286087|-0.17435339|-1.41369334|
## | |Yes|483|Inf | 2.1812242|-0.02898754|-2.07247287|
## +--------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +--------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)
f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)
# x=TRUE, y=TRUE used by resid() below
eq_OLR_03 <- polr(risk ~ building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ground_veg + conc_rainfall_water+tree+ wastewater + TC,
data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## building.L 0.26241262 0.3150563 0.8329070 2.024486e-01
## building.Q -0.72388871 0.3855956 -1.8773261 3.023671e-02
## ENTRUE 0.66638667 0.2615206 2.5481227 5.415218e-03
## DepTaludeAterroTRUE 0.84046001 0.6138799 1.3690952 8.548476e-02
## DepTaludeCorteTRUE 0.73204989 0.2325230 3.1482900 8.211434e-04
## crackTRUE 1.82548294 0.3367049 5.4216115 2.953207e-08
## leaning_wallTRUE 1.53503787 0.5057375 3.0352463 1.201696e-03
## scarsTRUE 4.15984030 0.4123002 10.0893489 3.078829e-24
## downward_floorTRUE 1.77891498 0.3831399 4.6429901 1.717014e-06
## tiltedTRUE 0.75098944 0.3222342 2.3305702 9.888017e-03
## ground_vegTRUE 0.87709262 0.2642600 3.3190523 4.516176e-04
## conc_rainfall_waterTRUE 1.98289853 0.5356525 3.7018373 1.070219e-04
## treeTRUE 0.06340334 0.2357134 0.2689849 3.939706e-01
## wastewaterTRUE 0.76213640 0.2242307 3.3988947 3.382938e-04
## TCTRUE 1.09953216 0.4125784 2.6650257 3.849122e-03
## R1|R2 2.11354366 0.6612664 3.1962061 6.962381e-04
## R2|R3 6.05886768 0.7347163 8.2465403 8.152307e-17
## R3|R4 11.62615237 0.8970678 12.9601717 1.028932e-38
stargazer((ctable), type="text", style="default", digits = 2)
##
## ========================================================
## Value Std. Error t value p value
## --------------------------------------------------------
## building.L 0.26 0.32 0.83 0.20
## building.Q -0.72 0.39 -1.88 0.03
## ENTRUE 0.67 0.26 2.55 0.01
## DepTaludeAterroTRUE 0.84 0.61 1.37 0.09
## DepTaludeCorteTRUE 0.73 0.23 3.15 0.001
## crackTRUE 1.83 0.34 5.42 0.0000
## leaning_wallTRUE 1.54 0.51 3.04 0.001
## scarsTRUE 4.16 0.41 10.09 0
## downward_floorTRUE 1.78 0.38 4.64 0.0000
## tiltedTRUE 0.75 0.32 2.33 0.01
## ground_vegTRUE 0.88 0.26 3.32 0.0005
## conc_rainfall_waterTRUE 1.98 0.54 3.70 0.0001
## treeTRUE 0.06 0.24 0.27 0.39
## wastewaterTRUE 0.76 0.22 3.40 0.0003
## TCTRUE 1.10 0.41 2.67 0.004
## R1| R2 2.11 0.66 3.20 0.001
## R2| R3 6.06 0.73 8.25 0
## R3| R4 11.63 0.90 12.96 0
## --------------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ground_veg + conc_rainfall_water+tree+ wastewater + TC,
data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ground_veg + conc_rainfall_water+tree+ wastewater + TC, fun=sf))
s
## as.numeric(risk) N= 529
##
## +-------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +-------------------+---+---+----+----------+-----------+-----------+
## |EN |No |348|Inf | 1.5288574|-0.50470003|-2.51645501|
## | |Yes|181|Inf | 4.0831713| 0.88173835|-1.35889539|
## +-------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeAterro |No |510|Inf | 1.9236870|-0.10204925|-2.11296423|
## | |Yes| 19|Inf | Inf| 2.14006616|-0.31845373|
## +-------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeCorte |No |310|Inf | 1.5561934|-0.39204209|-2.47793798|
## | |Yes|219|Inf | 2.9396428| 0.45518854|-1.52939520|
## +-------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +-------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +-------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +-------------------+---+---+----+----------+-----------+-----------+
## |downward_floor |No |469|Inf | 1.8270276|-0.29639401|-2.45750768|
## | |Yes| 60|Inf | Inf| 4.07753744|-0.26826399|
## +-------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +-------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +-------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water|No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +-------------------+---+---+----+----------+-----------+-----------+
## |tree |No |223|Inf | 1.3475083|-0.67972416|-2.37368101|
## | |Yes|306|Inf | 2.7150432| 0.41091471|-1.78415487|
## +-------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +-------------------+---+---+----+----------+-----------+-----------+
## |TC |No | 46|Inf | 0.6286087|-0.17435339|-1.41369334|
## | |Yes|483|Inf | 2.1812242|-0.02898754|-2.07247287|
## +-------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +-------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)
f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)
eq_OLR_04 <- polr(risk~ building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ground_veg + conc_rainfall_water+ wastewater + TC
, data= train.data
, method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_04))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## building.L 0.2629616 0.3149305 0.8349832 2.024486e-01
## building.Q -0.7161186 0.3841402 -1.8642117 3.023671e-02
## ENTRUE 0.6800541 0.2565437 2.6508314 5.415218e-03
## DepTaludeAterroTRUE 0.8446356 0.6141265 1.3753447 8.548476e-02
## DepTaludeCorteTRUE 0.7351022 0.2321836 3.1660390 8.211434e-04
## crackTRUE 1.8188662 0.3357861 5.4167409 2.953207e-08
## leaning_wallTRUE 1.5460019 0.5035353 3.0702953 1.201696e-03
## scarsTRUE 4.1664899 0.4115675 10.1234675 3.078829e-24
## downward_floorTRUE 1.7826202 0.3829802 4.6546014 1.717014e-06
## tiltedTRUE 0.7491251 0.3220702 2.3259686 9.888017e-03
## ground_vegTRUE 0.8997904 0.2504026 3.5933747 4.516176e-04
## conc_rainfall_waterTRUE 1.9855042 0.5356878 3.7064580 1.070219e-04
## wastewaterTRUE 0.7583775 0.2238244 3.3882696 3.939706e-01
## TCTRUE 1.1092735 0.4109917 2.6990168 3.382938e-04
## R1|R2 2.1133904 0.6612173 3.1962118 3.849122e-03
## R2|R3 6.0567924 0.7345492 8.2455914 6.962381e-04
## R3|R4 11.6267367 0.8971842 12.9591417 8.152307e-17
stargazer((ctable), type="text", style="default", digits=2)
##
## ========================================================
## Value Std. Error t value p value
## --------------------------------------------------------
## building.L 0.26 0.31 0.83 0.20
## building.Q -0.72 0.38 -1.86 0.03
## ENTRUE 0.68 0.26 2.65 0.01
## DepTaludeAterroTRUE 0.84 0.61 1.38 0.09
## DepTaludeCorteTRUE 0.74 0.23 3.17 0.001
## crackTRUE 1.82 0.34 5.42 0.0000
## leaning_wallTRUE 1.55 0.50 3.07 0.001
## scarsTRUE 4.17 0.41 10.12 0
## downward_floorTRUE 1.78 0.38 4.65 0.0000
## tiltedTRUE 0.75 0.32 2.33 0.01
## ground_vegTRUE 0.90 0.25 3.59 0.0005
## conc_rainfall_waterTRUE 1.99 0.54 3.71 0.0001
## wastewaterTRUE 0.76 0.22 3.39 0.39
## TCTRUE 1.11 0.41 2.70 0.0003
## R1| R2 2.11 0.66 3.20 0.004
## R2| R3 6.06 0.73 8.25 0.001
## R3| R4 11.63 0.90 12.96 0
## --------------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~ building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ground_veg + conc_rainfall_water+ wastewater + TC
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ground_veg + conc_rainfall_water+ wastewater + TC
, fun=sf))
s
## as.numeric(risk) N= 529
##
## +-------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +-------------------+---+---+----+----------+-----------+-----------+
## |EN |No |348|Inf | 1.5288574|-0.50470003|-2.51645501|
## | |Yes|181|Inf | 4.0831713| 0.88173835|-1.35889539|
## +-------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeAterro |No |510|Inf | 1.9236870|-0.10204925|-2.11296423|
## | |Yes| 19|Inf | Inf| 2.14006616|-0.31845373|
## +-------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeCorte |No |310|Inf | 1.5561934|-0.39204209|-2.47793798|
## | |Yes|219|Inf | 2.9396428| 0.45518854|-1.52939520|
## +-------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +-------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +-------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +-------------------+---+---+----+----------+-----------+-----------+
## |downward_floor |No |469|Inf | 1.8270276|-0.29639401|-2.45750768|
## | |Yes| 60|Inf | Inf| 4.07753744|-0.26826399|
## +-------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +-------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +-------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water|No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +-------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +-------------------+---+---+----+----------+-----------+-----------+
## |TC |No | 46|Inf | 0.6286087|-0.17435339|-1.41369334|
## | |Yes|483|Inf | 2.1812242|-0.02898754|-2.07247287|
## +-------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +-------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_05 <- polr(risk ~ building+ TC_mature_Soil+ DepTaludeAterro+ DepTaludeCorte+ construction_deposit+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_05))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## building.L 0.10723683 0.3193606 0.3357860 3.685161e-01
## building.Q -0.91765427 0.3970004 -2.3114692 1.040348e-02
## TC_mature_SoilTRUE 0.63636504 0.2236484 2.8453811 2.217916e-03
## DepTaludeAterroTRUE 0.38783963 0.6055040 0.6405236 2.609161e-01
## DepTaludeCorteTRUE 0.59709739 0.2486494 2.4013627 8.167069e-03
## construction_depositTRUE 0.04921662 0.2545155 0.1933737 4.233331e-01
## crackTRUE 1.82369931 0.3327584 5.4805510 2.120016e-08
## leaning_wallTRUE 1.54391550 0.5018794 3.0762680 1.048047e-03
## scarsTRUE 4.21133212 0.4090227 10.2960852 3.669369e-25
## downward_floorTRUE 1.61190796 0.3845368 4.1918172 1.383645e-05
## tiltedTRUE 0.86053067 0.3229448 2.6646373 3.853569e-03
## conc_rainfall_waterTRUE 1.96109102 0.5308295 3.6943895 1.102079e-04
## wastewaterTRUE 0.74653858 0.2247991 3.3209140 4.486159e-04
## ground_vegTRUE 1.06545025 0.2407255 4.4259959 4.799917e-06
## R1|R2 1.28345274 0.5544072 2.3150000 1.030647e-02
## R2|R3 5.21305377 0.6255862 8.3330704 3.938614e-17
## R3|R4 10.67191392 0.7783041 13.7117532 4.317295e-43
stargazer((ctable), type="text", style="default", digits = 2)
##
## =========================================================
## Value Std. Error t value p value
## ---------------------------------------------------------
## building.L 0.11 0.32 0.34 0.37
## building.Q -0.92 0.40 -2.31 0.01
## TC_mature_SoilTRUE 0.64 0.22 2.85 0.002
## DepTaludeAterroTRUE 0.39 0.61 0.64 0.26
## DepTaludeCorteTRUE 0.60 0.25 2.40 0.01
## construction_depositTRUE 0.05 0.25 0.19 0.42
## crackTRUE 1.82 0.33 5.48 0.0000
## leaning_wallTRUE 1.54 0.50 3.08 0.001
## scarsTRUE 4.21 0.41 10.30 0
## downward_floorTRUE 1.61 0.38 4.19 0.0000
## tiltedTRUE 0.86 0.32 2.66 0.004
## conc_rainfall_waterTRUE 1.96 0.53 3.69 0.0001
## wastewaterTRUE 0.75 0.22 3.32 0.0004
## ground_vegTRUE 1.07 0.24 4.43 0.0000
## R1| R2 1.28 0.55 2.32 0.01
## R2| R3 5.21 0.63 8.33 0
## R3| R4 10.67 0.78 13.71 0
## ---------------------------------------------------------
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~ building+ TC_mature_Soil+ DepTaludeAterro+ DepTaludeCorte+ construction_deposit+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~building+ TC_mature_Soil+ DepTaludeAterro+ DepTaludeCorte+ construction_deposit+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529
##
## +--------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC_mature_Soil |No |274|Inf | 1.5493340|-0.32397207|-2.21355147|
## | |Yes|255|Inf | 2.6390573| 0.26028310|-1.80555279|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeAterro |No |510|Inf | 1.9236870|-0.10204925|-2.11296423|
## | |Yes| 19|Inf | Inf| 2.14006616|-0.31845373|
## +--------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeCorte |No |310|Inf | 1.5561934|-0.39204209|-2.47793798|
## | |Yes|219|Inf | 2.9396428| 0.45518854|-1.52939520|
## +--------------------+---+---+----+----------+-----------+-----------+
## |construction_deposit|No |322|Inf | 1.6244195|-0.45488999|-2.39113849|
## | |Yes|207|Inf | 2.7880929| 0.60738036|-1.55814462|
## +--------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +--------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +--------------------+---+---+----+----------+-----------+-----------+
## |downward_floor |No |469|Inf | 1.8270276|-0.29639401|-2.45750768|
## | |Yes| 60|Inf | Inf| 4.07753744|-0.26826399|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +--------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water |No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +--------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +--------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +--------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +--------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
# x=TRUE, y=TRUE used by resid() below
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")
eq_OLR_06 <- polr(risk ~ building+ TC_mature_Soil+ DepTaludeCorte+ conc_rainfall_water + crack+ leaning_wall+ scars+ downward_floor+ tilted + wastewater+ ground_veg, data= train.data
, method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_06))
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )
ctable
## Value Std. Error t value p value
## building.L 0.0922464 0.3178444 0.290225 3.858220e-01
## building.Q -0.9277081 0.3965392 -2.339512 9.654477e-03
## TC_mature_SoilTRUE 0.6469508 0.2214729 2.921129 1.743828e-03
## DepTaludeCorteTRUE 0.6100576 0.2222423 2.745011 3.025442e-03
## conc_rainfall_waterTRUE 1.9638250 0.5308624 3.699311 1.080927e-04
## crackTRUE 1.8446220 0.3315722 5.563258 1.323916e-08
## leaning_wallTRUE 1.5775416 0.4978685 3.168591 7.658989e-04
## scarsTRUE 4.2263787 0.4087253 10.340388 2.313291e-25
## downward_floorTRUE 1.5969674 0.3818416 4.182277 1.443021e-05
## tiltedTRUE 0.8892745 0.3202906 2.776461 2.747710e-03
## wastewaterTRUE 0.7493833 0.2239424 3.346322 4.094556e-04
## ground_vegTRUE 1.0689621 0.2404899 4.444935 4.395921e-06
## R1|R2 1.2898202 0.5541111 2.327729 9.963262e-03
## R2|R3 5.2148533 0.6245506 8.349769 3.419838e-17
## R3|R4 10.6755386 0.7780199 13.721421 3.778476e-43
stargazer((ctable), type="text", style="default", digits = 2)
##
## ========================================================
## Value Std. Error t value p value
## --------------------------------------------------------
## building.L 0.09 0.32 0.29 0.39
## building.Q -0.93 0.40 -2.34 0.01
## TC_mature_SoilTRUE 0.65 0.22 2.92 0.002
## DepTaludeCorteTRUE 0.61 0.22 2.75 0.003
## conc_rainfall_waterTRUE 1.96 0.53 3.70 0.0001
## crackTRUE 1.84 0.33 5.56 0
## leaning_wallTRUE 1.58 0.50 3.17 0.001
## scarsTRUE 4.23 0.41 10.34 0
## downward_floorTRUE 1.60 0.38 4.18 0.0000
## tiltedTRUE 0.89 0.32 2.78 0.003
## wastewaterTRUE 0.75 0.22 3.35 0.0004
## ground_vegTRUE 1.07 0.24 4.44 0.0000
## R1| R2 1.29 0.55 2.33 0.01
## R2| R3 5.21 0.62 8.35 0
## R3| R4 10.68 0.78 13.72 0
## --------------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~ building+ TC_mature_Soil+ DepTaludeCorte+ conc_rainfall_water + crack+ leaning_wall+ scars+ downward_floor+ tilted + wastewater+ ground_veg
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~building+ TC_mature_Soil+ DepTaludeCorte+ conc_rainfall_water + crack+ leaning_wall+ scars+ downward_floor+ tilted + wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk) N= 529
##
## +-------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +-------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +-------------------+---+---+----+----------+-----------+-----------+
## |TC_mature_Soil |No |274|Inf | 1.5493340|-0.32397207|-2.21355147|
## | |Yes|255|Inf | 2.6390573| 0.26028310|-1.80555279|
## +-------------------+---+---+----+----------+-----------+-----------+
## |DepTaludeCorte |No |310|Inf | 1.5561934|-0.39204209|-2.47793798|
## | |Yes|219|Inf | 2.9396428| 0.45518854|-1.52939520|
## +-------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water|No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +-------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +-------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +-------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +-------------------+---+---+----+----------+-----------+-----------+
## |downward_floor |No |469|Inf | 1.8270276|-0.29639401|-2.45750768|
## | |Yes| 60|Inf | Inf| 4.07753744|-0.26826399|
## +-------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +-------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +-------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +-------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +-------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
Equation 07
f7 <- lrm(risk~options(contrasts=c(1,2,3), building)+ angle+EN+TC+ TC_mature_Soil+banana+TC_saprolito+ garbage+ landfill + construction_deposit + drainage + leak+ conc_rainfall_water+ crack+ tilted + leaning_wall + scars + tree + ground_veg , data= train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f6), type=“text”, style=“default”)
eq_OLR_07 <- polr(risk~ angle+ building+ EN+ TC+ landfill+ garbage+ construction_deposit+ crack+ leaning_wall + scars+ tilted+ conc_rainfall_water+ leak+ tree+ wastewater+ ground_veg+ banana
, data= train.data
, method = "logistic", Hess = TRUE)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- coef(summary(eq_OLR_07))
ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
## Value Std. Error t value p value
## angleB -0.913706215 1.5019548 -0.60834468 3.858220e-01
## angleC 0.223772028 1.4847154 0.15071712 9.654477e-03
## angleD 0.776051365 1.4803118 0.52424857 1.743828e-03
## angleE 1.698879667 1.4946733 1.13662278 3.025442e-03
## building.L 0.315444587 0.3201773 0.98521836 1.080927e-04
## building.Q -0.779608789 0.3861476 -2.01893967 1.323916e-08
## ENTRUE 0.416799545 0.2845248 1.46489725 7.658989e-04
## TCTRUE 1.013541004 0.4077912 2.48544081 2.313291e-25
## landfillTRUE 0.353984781 0.2493409 1.41968191 1.443021e-05
## garbageTRUE 0.499703046 0.3507553 1.42464878 2.747710e-03
## construction_depositTRUE 0.034017604 0.3392781 0.10026465 4.094556e-04
## crackTRUE 1.633402258 0.3374018 4.84111903 4.395921e-06
## leaning_wallTRUE 1.481760119 0.4912784 3.01613098 9.963262e-03
## scarsTRUE 4.411552419 0.4177655 10.55987643 3.419838e-17
## tiltedTRUE 0.946739751 0.3260472 2.90368911 3.778476e-43
## conc_rainfall_waterTRUE 1.830024475 0.5871908 3.11657555 3.858220e-01
## leakTRUE 0.110519544 0.2370412 0.46624622 9.654477e-03
## treeTRUE -0.035690236 0.2457197 -0.14524774 1.743828e-03
## wastewaterTRUE 0.818820842 0.2322368 3.52580170 3.025442e-03
## ground_vegTRUE 0.756267159 0.2683732 2.81796819 1.080927e-04
## bananaTRUE 0.005044643 0.2627487 0.01919949 1.323916e-08
## R1|R2 2.175030159 1.5678979 1.38722692 7.658989e-04
## R2|R3 6.352307282 1.6038661 3.96062205 2.313291e-25
## R3|R4 11.809412362 1.6839692 7.01284344 1.443021e-05
stargazer((ctable), type="text", style="default", digits = 2)
##
## =========================================================
## Value Std. Error t value p value
## ---------------------------------------------------------
## angleB -0.91 1.50 -0.61 0.39
## angleC 0.22 1.48 0.15 0.01
## angleD 0.78 1.48 0.52 0.002
## angleE 1.70 1.49 1.14 0.003
## building.L 0.32 0.32 0.99 0.0001
## building.Q -0.78 0.39 -2.02 0
## ENTRUE 0.42 0.28 1.46 0.001
## TCTRUE 1.01 0.41 2.49 0
## landfillTRUE 0.35 0.25 1.42 0.0000
## garbageTRUE 0.50 0.35 1.42 0.003
## construction_depositTRUE 0.03 0.34 0.10 0.0004
## crackTRUE 1.63 0.34 4.84 0.0000
## leaning_wallTRUE 1.48 0.49 3.02 0.01
## scarsTRUE 4.41 0.42 10.56 0
## tiltedTRUE 0.95 0.33 2.90 0
## conc_rainfall_waterTRUE 1.83 0.59 3.12 0.39
## leakTRUE 0.11 0.24 0.47 0.01
## treeTRUE -0.04 0.25 -0.15 0.002
## wastewaterTRUE 0.82 0.23 3.53 0.003
## ground_vegTRUE 0.76 0.27 2.82 0.0001
## bananaTRUE 0.01 0.26 0.02 0
## R1| R2 2.18 1.57 1.39 0.001
## R2| R3 6.35 1.60 3.96 0
## R3| R4 11.81 1.68 7.01 0.0000
## ---------------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~ building+ angle+ EN+ TC+ landfill+ garbage+ banana+ leak+ conc_rainfall_water+ tree+ wastewater+ scars+ tilted+ ground_veg+ construction_deposit+ crack+ leaning_wall
,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)
sf <- function (y) {
c('y>=1' = qlogis(mean(y>=1)),
'y>=2' = qlogis(mean(y>=2)),
'y>=3' = qlogis(mean(y>=3)),
'y>=4' = qlogis(mean(y>=4)))
}
s<-with(train.data, summary(as.numeric(risk)~ building+ angle+ EN+ TC+ landfill+ garbage+ banana+ leak+ conc_rainfall_water+ tree+ wastewater+ scars+ tilted+ ground_veg+ construction_deposit+ crack+ leaning_wall
, fun=sf))
s
## as.numeric(risk) N= 529
##
## +--------------------+---+---+----+----------+-----------+-----------+
## | | |N |y>=1|y>=2 |y>=3 |y>=4 |
## +--------------------+---+---+----+----------+-----------+-----------+
## |building |B |459|Inf | 1.9139271|-0.22314355|-2.49438539|
## | |W | 39|Inf | 2.4849066| 1.51982575|-0.05129329|
## | |M | 31|Inf | 2.2335922| 1.05605267|-0.89381788|
## +--------------------+---+---+----+----------+-----------+-----------+
## |angle |A | 3|Inf | 0.6931472| -Inf| -Inf|
## | |B | 46|Inf |-0.3513979|-1.89711998|-3.80666249|
## | |C | 82|Inf | 1.6691571|-1.00330211|-3.27083556|
## | |D |293|Inf | 2.6137395| 0.33764251|-1.84451003|
## | |E |105|Inf | 3.2288262| 0.28768207|-1.50990832|
## +--------------------+---+---+----+----------+-----------+-----------+
## |EN |No |348|Inf | 1.5288574|-0.50470003|-2.51645501|
## | |Yes|181|Inf | 4.0831713| 0.88173835|-1.35889539|
## +--------------------+---+---+----+----------+-----------+-----------+
## |TC |No | 46|Inf | 0.6286087|-0.17435339|-1.41369334|
## | |Yes|483|Inf | 2.1812242|-0.02898754|-2.07247287|
## +--------------------+---+---+----+----------+-----------+-----------+
## |landfill |No |331|Inf | 1.5490288|-0.57746278|-2.74406064|
## | |Yes|198|Inf | 3.3063633| 0.88119941|-1.28222500|
## +--------------------+---+---+----+----------+-----------+-----------+
## |garbage |No |355|Inf | 1.7181262|-0.33550652|-2.53796121|
## | |Yes|174|Inf | 2.6958549| 0.56639547|-1.30906301|
## +--------------------+---+---+----+----------+-----------+-----------+
## |banana |No |363|Inf | 1.5995532|-0.40776132|-2.23766555|
## | |Yes|166|Inf | 3.7013020| 0.78495473|-1.59504917|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leak |No |345|Inf | 1.6625477|-0.35737892|-2.59338729|
## | |Yes|184|Inf | 2.8564702| 0.55748132|-1.31317210|
## +--------------------+---+---+----+----------+-----------+-----------+
## |conc_rainfall_water |No | 23|Inf |-1.0414539| -Inf| -Inf|
## | |Yes|506|Inf | 2.2556682| 0.04743973|-1.95043504|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tree |No |223|Inf | 1.3475083|-0.67972416|-2.37368101|
## | |Yes|306|Inf | 2.7150432| 0.41091471|-1.78415487|
## +--------------------+---+---+----+----------+-----------+-----------+
## |wastewater |No |220|Inf | 1.3031440|-0.57931204|-3.04452244|
## | |Yes|309|Inf | 2.7829515| 0.33314445|-1.57488553|
## +--------------------+---+---+----+----------+-----------+-----------+
## |scars |No |322|Inf | 1.3746888|-1.55814462|-4.37575702|
## | |Yes|207|Inf | Inf| 3.92691162|-0.91967483|
## +--------------------+---+---+----+----------+-----------+-----------+
## |tilted |No |433|Inf | 1.7519136|-0.46550250|-2.59773918|
## | |Yes| 96|Inf | 4.5538769| 3.13549422|-0.64662716|
## +--------------------+---+---+----+----------+-----------+-----------+
## |ground_veg |No |162|Inf | 0.9249488|-1.36330484|-2.95751106|
## | |Yes|367|Inf | 2.9077635| 0.47177511|-1.73567000|
## +--------------------+---+---+----+----------+-----------+-----------+
## |construction_deposit|No |322|Inf | 1.6244195|-0.45488999|-2.39113849|
## | |Yes|207|Inf | 2.7880929| 0.60738036|-1.55814462|
## +--------------------+---+---+----+----------+-----------+-----------+
## |crack |No |444|Inf | 1.7812882|-0.40171276|-2.73724936|
## | |Yes| 85|Inf | 4.4308168| 3.00815479|-0.30830136|
## +--------------------+---+---+----+----------+-----------+-----------+
## |leaning_wall |No |497|Inf | 1.8940383|-0.15726498|-2.23582188|
## | |Yes| 32|Inf | Inf| 2.70805020|-0.12516314|
## +--------------------+---+---+----+----------+-----------+-----------+
## |Overall | |529|Inf | 1.9654973|-0.04159390|-2.00105091|
## +--------------------+---+---+----+----------+-----------+-----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)
predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_01, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
## predictedLevel1
## R1 R2 R3 R4
## R1 5 21 1 0
## R2 2 78 7 0
## R3 0 20 52 11
## R4 0 1 17 9
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1
## [1] 0.3571429
predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
## predictedLevel2
## R1 R2 R3 R4
## R1 15 11 1 0
## R2 7 75 5 0
## R3 0 21 55 7
## R4 0 1 16 10
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.3080357
predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_03, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
## predictedLevel3
## R1 R2 R3 R4
## R1 6 20 1 0
## R2 2 76 9 0
## R3 0 18 57 8
## R4 0 1 16 10
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.3348214
predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly
predictedScores1 <- predict(eq_OLR_04, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
## predictedLevel4
## R1 R2 R3 R4
## R1 6 20 1 0
## R2 2 78 7 0
## R3 0 19 57 7
## R4 0 1 16 10
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.3258929
predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly
predictedScores5 <- predict(eq_OLR_05, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
## predictedLevel5
## R1 R2 R3 R4
## R1 5 21 1 0
## R2 2 78 7 0
## R3 0 19 57 7
## R4 0 1 17 9
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.3348214
predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly
predictedScores6 <- predict(eq_OLR_06, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
## predictedLevel6
## R1 R2 R3 R4
## R1 5 21 1 0
## R2 2 78 7 0
## R3 0 20 56 7
## R4 0 1 17 9
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.3392857
predictedLevel7 <- predict(eq_OLR_07, test.data) # predict the levels directly
predictedScores7 <- predict(eq_OLR_07, test.data, type="p")
# predict the probabilites
## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel7)
## predictedLevel7
## R1 R2 R3 R4
## R1 14 12 1 0
## R2 7 74 6 0
## R3 0 23 57 3
## R4 0 1 17 9
p7 <- mean(as.character(test.data$risk) != as.character(predictedLevel7))
p7
## [1] 0.3125
#Table
df2 <- data.frame(
"Equations"=c(1:7),
"Predicted"=c(1-p1,
1-p2,
1-p3,
1-p4,
1-p5,
1-p6,
1-p7
)
)
df2
## Equations Predicted
## 1 1 0.6428571
## 2 2 0.6919643
## 3 3 0.6651786
## 4 4 0.6741071
## 5 5 0.6651786
## 6 6 0.6607143
## 7 7 0.6875000